# -*- coding: utf8 -*-
#
# Copyright (c) 2009 Matías Ribecky <status-notifications@mribecky.com.ar>
#
# This file is part of status-notifications.
# 
# status-notifications is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# status-notifications is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with status-notifications.  If not, see <http://www.gnu.org/licenses/>.

'''Has the different implementations for the notifiers.'''

import logging

LOGGER = logging.getLogger('statusnotifications.notifier')

class Notifier(object):
    '''Abstract base class for the notifiers.'''

    name = None
    options = {}

    @classmethod
    def plugin_list(cls):
        '''Return a set of the plugin names.'''

        plugin_list = set()
        for sub_cls in cls.__subclasses__():
            plugin_list |= sub_cls.plugin_list()

        if cls.name:
            plugin_list.add(cls.name)

        return plugin_list

    @classmethod
    def get_plugin(cls, name):
        '''Get a plugin by name.'''
        if cls.name == name:
            return cls
        else:
            for sub_cls in cls.__subclasses__():
                found = sub_cls.get_plugin(name)
                if found:
                    return found
            return None

    def notify(self, status):
        '''Notify of the status.'''

        LOGGER.info("%s notifier: notifying of status %s" %
                    (self.name, status.id))

    def __init__(self, config):
        '''Create a notifier.'''

        self.config = config
